package com.ruoyi.school.controller;

import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.tokenizer.TokenizerUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.school.domain.Goods;
import com.ruoyi.school.domain.QueryPageParam;
import org.apache.catalina.User;
import org.apache.catalina.User;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.school.domain.Push;
import com.ruoyi.school.service.IPushService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上传信息Controller
 *
 * @author ruoyi
 * @date 2024-02-01
 */
@RestController
@RequestMapping("/school/schoolpush")
public class PushController extends BaseController
{
    @Autowired
    private IPushService pushService;

    /**
     * 查询上传信息列表
     */
    @PreAuthorize("@ss.hasPermi('school:schoolpush:list')")
    @GetMapping("/list")
    public TableDataInfo list(Push push)
    {

        startPage();
        List<Push> list = pushService.selectPushList(push);
        return getDataTable(list);
    }

    /**
     * 导出上传信息列表
     */
    @PreAuthorize("@ss.hasPermi('school:schoolpush:export')")
    @Log(title = "上传信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Push push)
    {
        List<Push> list = pushService.selectPushList(push);
        ExcelUtil<Push> util = new ExcelUtil<Push>(Push.class);
        util.exportExcel(response, list, "上传信息数据");
    }

    /**
     * 获取上传信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:schoolpush:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        return success(pushService.selectPushById(id));
    }

    /**
     * 新增上传信息
     */
    @PreAuthorize("@ss.hasPermi('school:schoolpush:add')")
    @Log(title = "上传信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Push push)
    {

//        if(push.getId()==null){
//            push.setTime(DateUtil.today());
//        }
        push.setName(SecurityUtils.getLoginUser().getUsername());
        push.setTime(DateUtil.today());

        return toAjax(pushService.insertPush(push));
    }

    /**
     * 修改上传信息
     */
    @PreAuthorize("@ss.hasPermi('school:schoolpush:edit')")
    @Log(title = "上传信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Push push)
    {
        return toAjax(pushService.updatePush(push));
    }

    /**
     * 删除上传信息
     */
    @PreAuthorize("@ss.hasPermi('school:schoolpush:remove')")
    @Log(title = "上传信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pushService.deletePushByIds(ids));
    }
}
